package com.five.bi.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.five.bi.mapper.SchemaMapper;
import com.five.bi.model.SchemaDO;
import com.five.bi.model.vo.SchemaVO;
import com.five.bi.service.SchemaService;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @Description
 * @Author xuzhihong
 * @Version 1.0
 * @Date 2022/8/4
 */
@Service
public class SchemaServiceImpl implements SchemaService {

    @Resource
    private SchemaMapper schemaMapper;

    @Override
    public List<SchemaVO> listBySetId(String setId) {
        List<SchemaDO> schemaDOList = schemaMapper.selectList(new QueryWrapper<SchemaDO>().eq("set_id", setId));

        List<SchemaVO> schemaVOList = schemaDOList.stream().map(schemaDO -> {
            SchemaVO schemaVO = new SchemaVO();
            BeanUtils.copyProperties(schemaDO, schemaVO);
            return schemaVO;
        }).collect(Collectors.toList());

        return schemaVOList;
    }

    @Override
    public void insertBatch(List<SchemaDO> list) {
        schemaMapper.insertBatch(list);
    }
}
